/**
 * 
 */
package com.laozhao.test;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.util.Timer;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JWindow;

import com.laozhao.EasySales.business.SystemServer;
import com.laozhao.EasySales.control.MainWindowsAction;
import com.laozhao.EasySales.model.UserModel;
import com.laozhao.dreamframe.util.ToolsUtil;

/**
 * @author laozhao
 *
 */
public class StarUI extends JWindow implements Runnable {

	protected SystemServer sys = new SystemServer();
	String filename= ToolsUtil.getRoot() + "\\img\\login.jpg";
	  //Logo图像文件的文件名
	  public StarUI(String name,JFrame jf) {
//	    filename = name;
	    MyTask myTask = new MyTask(this,jf);
	    Timer myTimer =new Timer();
	    myTimer.schedule(myTask, 1500, 100);   //delay period
	  }
	  public void run() {
	    ImageIcon ig = new ImageIcon(filename);
	    JButton btn = new JButton(ig);
	    //将图片给JButton显示
	    getContentPane().add(btn);
	    //将显示图片的btn加到JPanel里
	    Toolkit kit = Toolkit.getDefaultToolkit();
	    Dimension screenSize = kit.getScreenSize();
	    //获得屏幕的大小
	    int nImgWidth = ig.getIconWidth();
	    int nImgHeight = ig.getIconHeight();
	    this.setLocation(screenSize.width / 2 - nImgWidth / 2,screenSize.height / 2 - nImgHeight / 2);
	    //将Logo窗口显示在屏幕宽的1/2，高的1/2处           
	    //setLocationRelativeTo(null);
	    setSize(nImgWidth, nImgHeight);
	    //将Logo窗口大小设成图像的大小
	    this.setAlwaysOnTop(true);
	    //将Logo窗口显示为最前面的窗口
	    setVisible(true);     
	  }  
	  

	  public class MyTask extends java.util.TimerTask
	  {
	    private JWindow m_jf;
	    private JFrame m_main;   
	    public MyTask(JWindow jf,JFrame main)
	    {
	      super();     
	      m_jf=jf;
	      m_main=main;
	    }
	    public void run()
	    {     
	      m_jf.dispose();       
	      m_main.setAlwaysOnTop(true);       
	      cancel();     
	    }   
	  }
	  
	  public static void main(String args[]) {
		    java.awt.EventQueue.invokeLater(new Runnable() {
		        public void run() { 
		        	UserModel user = new UserModel();
		        MainWindowsAction jmain=new MainWindowsAction(user);
//		          Runnable sf=new StarUI("d:\\link.jpg",jmain);                     
//		          Thread Splashth=new Thread(sf,"recv");
//		          Splashth.start();
//		          jmain.setVisible(true); 
		          }
		    });
		  }

}
